﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using OFB.BLL.Context;
using OFB.BLL.ViewModel;
using OFB.Domain;

namespace OFB.BLL.Repository
{
    public class FeedbackkBLL : IFeedbackkBLL
    {
        private readonly FeedbackkContext context;

        public FeedbackkBLL()
        {
            context = new FeedbackkContext();
        }

        public ICollection<FeedbackkViewModel> Filter(FeedbackFilterViewModel filter)
        {
            return context.FeedbackViewModel.Init("FeedbackViewModel_Filter",
                context.FeedbackViewModel.BuildParameter("CourseName", DbType.String, filter.CourseName),
                context.FeedbackViewModel.BuildParameter("SubjectName", DbType.String, filter.SubjectName),
                context.FeedbackViewModel.BuildParameter("TopicName", DbType.String, filter.TopicName),
                context.FeedbackViewModel.BuildParameter("TrainerName", DbType.String, filter.TrainerName),
                context.FeedbackViewModel.BuildParameter("IsDisabled", DbType.Int32, filter.IsDisabled),
                context.FeedbackViewModel.BuildParameter("FromDate", DbType.DateTime, filter.FromDate),
                context.FeedbackViewModel.BuildParameter("ToDate", DbType.DateTime, filter.ToDate))
                                                .MapCollection<FeedbackkViewModel>()
                                                .GetCollection();
        }

        public FeedbackkViewModel Search(int feedbackId)
        {
            return context.FeedbackViewModel.Init("FeedbackViewModel_Search", context.FeedbackViewModel.BuildParameter("FbId", DbType.Int32, feedbackId))
                                                .Map()
                                                .Get();
        }

        public ICollection<Trainee> UnFeedbackTrainee(int feedbackId)
        {
            return context.Trainee.Init("FeedbackTraineeMissing_ListAll", context.FeedbackViewModel.BuildParameter("FbId", DbType.Int32, feedbackId))
                                                .MapCollection<Trainee>()
                                                .GetCollection();
        }

        public bool ChangeStatus(int feedbackId)
        {
            IDataParameter para = context.FeedbackViewModel.BuildParameter("Valid", DbType.Boolean, ParameterDirection.Output);
            context.FeedbackViewModel.Execute("Feedback_ChangeStatus", context.FeedbackViewModel.BuildParameter("FbId", DbType.Int32, feedbackId),
                para);
            return Convert.ToBoolean(para.Value);
        }
    }
}
